package com.agileai.bpm.controller.emulation;

import java.util.List;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

import com.agileai.bpm.bizmoduler.emulation.WfOwnDraftTaskManage;
import com.agileai.domain.DataParam;
import com.agileai.domain.DataRow;
import com.agileai.hotweb.annotation.PageAction;
import com.agileai.hotweb.controller.core.StandardListHandler;
import com.agileai.hotweb.renders.AjaxRenderer;
import com.agileai.hotweb.renders.LocalRenderer;
import com.agileai.hotweb.renders.ViewRenderer;

public class WfOwnDraftTaskListHandler extends StandardListHandler{
	public WfOwnDraftTaskListHandler(){
		super();
		this.serviceId = buildServiceId(WfOwnDraftTaskManage.class);
	}
	public ViewRenderer prepareDisplay(DataParam param){
		mergeParam(param);
		initParameters(param);
		this.setAttributes(param);
		List<DataRow> rsList = getService().findRecords(param);
		this.setRsList(rsList);
		processPageAttributes(param);
		return new LocalRenderer(getPage());
	}
	public ViewRenderer doQueryAction(DataParam param){
		param.put("WFP_ID",param.get("CUR_WFP_ID"));
		return prepareDisplay(param);
	}
	@PageAction
  	public ViewRenderer retrieveIds(DataParam param) throws JSONException{
  		String responseText = "";
  		DataRow rsRow = getService().getRecord(param);
  		
  		JSONObject jsonObject = new JSONObject();  
        jsonObject.put("ModifyUrl", rsRow.getString("WFP_MODIFY_URL"));
        jsonObject.put("BizId", rsRow.getString("WWD_BIZ_ID"));
        String json = jsonObject.toString();
  		responseText=json;
  		return new AjaxRenderer(responseText);
  	}
	protected WfOwnDraftTaskManage getService() {
		return (WfOwnDraftTaskManage)this.lookupService(this.getServiceId());
	}
}
